use serde::{Deserialize, Serialize};
use std::net::{IpAddr, Ipv4Addr};
// use crate::config::logger::LogLevel;

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Config {
    /// IP address to serve on. **(default: `127.0.0.1`)**
    pub address: IpAddr,
    /// Port to serve on. **(default: `8000`)**
    pub port: u16,
    /// Number of future-executing threads. **(default: `num cores`)**
    pub workers: usize,
    /// Keep-alive timeout in seconds; disabled when `0`. **(default: `5`)**
    pub keep_alive: u32,
    // /// Max level to log. **(default: _debug_ `normal` / _release_ `critical`)**
    // pub log_level: LogLevel,
    // /// Whether to use colors and emoji when logging. **(default: `true`)**
    // #[serde(deserialize_with = "figment::util::bool_from_str_or_int")]
    pub cli_colors: bool,
    // /// The secret key for signing and encrypting. **(default: `0`)**
    // pub secret_key: SecretKey,
    // /// The TLS configuration, if any. **(default: `None`)**
    // pub tls: Option<TlsConfig>,
    // /// Streaming read size limits. **(default: [`Limits::default()`])**
    // pub limits: Limits,
    // /// Whether `ctrl-c` initiates a server shutdown. **(default: `true`)**
    // #[serde(deserialize_with = "figment::util::bool_from_str_or_int")]
    pub ctrl_c: bool,

    pub protocol: Protocol,

    pub node_heart: bool,
}

impl Config {
    pub fn debug_default_tcp() -> Config {
        // use loom::
        Config {
            address: Ipv4Addr::new(0, 0, 0, 0).into(),
            port: 8080,
            workers: num_cpus::get(),
            keep_alive: 5,
            cli_colors: true,
            ctrl_c: true,
            protocol: Protocol::TCP,
            node_heart: true,
        }
    }

    pub fn debug_default_udp() -> Config {
        // use loom::
        Config {
            address: Ipv4Addr::new(0, 0, 0, 0).into(),
            port: 8080,
            workers: num_cpus::get(),
            keep_alive: 5,
            cli_colors: true,
            ctrl_c: true,
            protocol: Protocol::UDP,
            node_heart: true,
        }
    }
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub enum Protocol {
    TCP,
    UDP,
}
